from multiprocessing import Queue
import multiprocessing
import redis


class AsyncReportProcess(multiprocessing.Process):
    def __init__(self, q: Queue, redis_addr: str, redis_port: int, ml_sp_key: str):
        super().__init__()
        self.queue = q
        self.redis = redis.Redis(host=redis_addr, port=redis_port, db=0)
        self.ml_sp_key = ml_sp_key

    def run(self):
        while True:
            data = self.queue.get()
            if data is None:
                break
            self.redis.set(self.ml_sp_key, data)